<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title> - 课程列表</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/plugins/toastr/toastr.min.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <!-- jqgrid-->
    <link href="css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
    <style>
        td{
            text-align: center;
        }

        th{
            text-align: center;
        }

        .form-group{
            margin-top: 10px;
            overflow: hidden;
        }
    </style>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div id="loading" class="ibox-content">
        <div class="spiner-example">
            <div class="sk-spinner sk-spinner-wave">
                <div class="sk-rect1"></div>
                <div class="sk-rect2"></div>
                <div class="sk-rect3"></div>
                <div class="sk-rect4"></div>
                <div class="sk-rect5"></div>
            </div>
        </div>
        <p id="jindu" style="text-align: center;">数据加载中...</p>
    </div>



    <div class="row">
        <table class="table table-striped">
            <thead>
            <tr>
                <th>ID</th>
                <th>名称</th>
                <th>上课地点</th>
                <th>上课时间</th>
                <th>课程内容</th>
                <th>课程周期</th>
                <th>课程封面</th>
                <th>选课学生</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody id="table">
            <!--<tr>-->
                <!--<td>Tanmay</td>-->
                <!--<td>Bangalore</td>-->
                <!--<td>560001</td>-->
            <!--</tr>-->
            </tbody>
        </table>
    </div>
</div>


<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<!-- 自定义js -->
<script src="js/content.js?v=1.0.0"></script>
<!-- jqGrid -->
<script src="js/plugins/jqgrid/i18n/grid.locale-cn.js?0820"></script>
<script src="js/plugins/jqgrid/jquery.jqGrid.min.js?0820"></script>
<script src="js/plugins/toastr/toastr.min.js"></script>


<script src="js/zhangyue5.4.js"></script>

</body>
<script>

    if(!mydata.get('id') || mydata.get('id')==""){
        window.location.href='login.html';
    }

    shuju.set('id',mydata.get('id'));
    shuju.set('method','getmylist');
    shuju.getshuju('kecheng',{
        success:function(data){
            if(data.code==200){
                let info = data.data;
                let html = [];
                for(let i=0;i<info.length;i++){
                    html.push(gethtml(info[i]));
                }
                document.getElementById('table').innerHTML=html.join('');
                document.getElementById('loading').style.display='none';
            }
        },
        error:function(e){

        }
    });


    var gethtml=function(obj){
        return `
                  <tr id="tr${obj.id}" data-for="${obj.id}">
                     <td>${obj.id}</td>
                     <td>${obj.name}</td>
                     <td>${obj.didian}</td>
                     <td>${obj.shijian}</td>
                     <td>${obj.neirong}</td>
                     <td>${obj.zhouqi}</td>
                     <td><img src="${obj.fengmian}" style="width: 200px;height: 150px"></td>
                     <td><a href="xuesheng_list.html?kid=${obj.id}">查看</a></td>
                     <td><button data-for="${obj.id}" class="btn btn-success">编辑</button><button style="margin-left: 15px" data-for="${obj.id}" class="btn btn-danger">删除</button></td>
                  </tr>
                `
    };

    document.getElementById('table').addEventListener('click',function(e){
        if(e.target && e.target.nodeName=='BUTTON'){
            let obj = e.target;
            let kid = obj.dataset.for;
            if(obj.innerHTML=='编辑'){
                window.location.href='kecheng_bianji.html?kid='+kid;
            }
            if(obj.innerHTML=='删除'){
                if(confirm('是否确认删除')){
                    shuju.set('kid',kid);
                    shuju.set('tid',mydata.get('id'));
                    shuju.set('method','delete');
                    shuju.getshuju('kecheng',{
                        success:function(data){
                            if(data.code==200){
                                toastr.success('删除成功','系统提示');
                                $("#tr"+kid).remove();
                            }else{
                                toastr.error('删除失败','系统提示');
                            }
                        },
                        error:function(e){
                            toastr.error('删除失败','系统提示');
                        }
                    })
                }
            }
        }
    })

</script>

</html>